package com.dz.fz.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class myUtils {
    public static Date String2Date(String strDate, String strPattern) {
        Date date = null;
        if (strDate != null && !strDate.equals("")) {
            strPattern = strPattern == null  ? "yyyy-MM-dd HH:mm:ss" : strPattern;
            SimpleDateFormat sdf = new SimpleDateFormat(strPattern);
            try {
                date = sdf.parse(strDate);
            } catch (Exception e) {
                System.out.println("时间转换发生错误" + e.getMessage());
            }
        }
        return date;
    }

    public static String Date2String(Date date,String strPattern){
        String strDate = null;
        if(strDate !=null && !strDate.equals("")){
            strPattern = strPattern == null ? "yyyy-MM-dd HH:mm:ss":strPattern;
            SimpleDateFormat sdf = new SimpleDateFormat(strPattern);
            strDate = sdf.format(date);
        }
        return strDate;
    }
}
